package Service;

import DAO.CommentDAO;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "deleteComment", value = "/deleteComment")
public class deleteComment extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int deleteWhich= Integer.parseInt(request.getParameter("deleteWhich"));
        int bid= Integer.parseInt(request.getParameter("bid"));
        try {
            CommentDAO.deleteCom(bid,deleteWhich);
            request.setAttribute("bid",bid);//回去
            request.getRequestDispatcher("getBook2").forward(request,response);
        } catch (SQLException e) {
            throw new RuntimeException("删除评论失败");
        }
    }
}
